package com.gxuwz.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.google.gson.Gson;
import com.gxuwz.core.model.Cols;
import com.gxuwz.core.model.Page;
import com.gxuwz.core.util.MainUtil;
import com.gxuwz.core.util.UidUtils;
import com.gxuwz.core.web.action.BaseAction;
import com.gxuwz.pojo.Info;
import com.gxuwz.service.IInfoService;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;


public class InfoAction extends BaseAction implements Preparable, ModelDriven<Info>{


	protected static final String ACADEMY_JSP = "/WEB-INF/page/info/info_academy.jsp";  
	protected static final String ADD_ACADEMY_JSP = "/WEB-INF/page/info/info_add_academy.jsp";  
	protected static final String EDIT_ACADEMY_JSP = "/WEB-INF/page/info/info_edit_academy.jsp"; 
	
	protected static final String MAJOR_JSP = "/WEB-INF/page/info/info_major.jsp";  
	protected static final String ADD_MAJOR_JSP = "/WEB-INF/page/info/info_add_major.jsp";  
	protected static final String EDIT_MAJOR_JSP = "/WEB-INF/page/info/info_edit_major.jsp"; 
	
	protected static final String CLASS_JSP = "/WEB-INF/page/info/info_class.jsp";  
	protected static final String ADD_CLASS_JSP = "/WEB-INF/page/info/info_add_class.jsp";  
	protected static final String EDIT_CLASS_JSP = "/WEB-INF/page/info/info_edit_class.jsp"; 
	
	protected static final String UNIT_JSP = "/WEB-INF/page/info/info_list_unit.jsp";  
	protected static final String ADD_UNIT_JSP = "/WEB-INF/page/info/info_add_unit.jsp";  
	protected static final String EDIT_UNIT_JSP = "/WEB-INF/page/info/info_edit_unit.jsp"; 
	
	
	protected static final String LIST_JSP = "/WEB-INF/page/info/info_list.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/info/info_edit.jsp"; 
	protected static final String ADD_JSP = "/WEB-INF/page/info_add.jsp"; 
	protected static final String TOPIC_ADD_JSP = "/WEB-INF/page/info_topic_add.jsp"; 

	@Autowired
	private IInfoService infoService;
	
	private Page pageUtil;
	private Info info;
	
	private String result;


	/**
	 * 模糊查询打开页面
	 */
	public void list(){
		pageUtil = new Page();
		pageUtil.setCode(0);
		pageUtil.setData(infoService.findByEntity(info));
		pageUtil.setCount(pageUtil.getData().size());
		reJson(pageUtil);
	}
	
	/**
	 * 获得数据（下拉框）,准确数据
	 */
	public void getList(){
		if("".equals(info.getInfoParent())){
			info.setInfoParent(null);
		}
		reJson(infoService.findByExample(info));
		return;
	}
	
	public void del(){
		infoService.remove(info);
		return;
	}
	
	public void add(){
		infoService.save(info);
		return;
	}
	
	public void update(){
		infoService.update(info);
		return;
	}
	
	public String toEditClass(){
		info = infoService.findById(info.getId());
		setForwardView(EDIT_CLASS_JSP);
		return SUCCESS;
	}
	
	public String toEditMajor(){
		info = infoService.findById(info.getId());
		setForwardView(EDIT_MAJOR_JSP);
		return SUCCESS;
	}
	
	public String toEditAcademy(){
		info = infoService.findById(info.getId());
		setForwardView(EDIT_ACADEMY_JSP);
		return SUCCESS;
	}
	
	public String toAddAcademy(){
		setForwardView(ADD_ACADEMY_JSP);
		return SUCCESS;
	}
	
	public String toAddMajor(){
		setForwardView(ADD_MAJOR_JSP);
		return SUCCESS;
	}
	
	public String toAddClass(){
		if(MainUtil.noNull(result)){
			info = infoService.findById(Integer.valueOf(result));
		}
		
		setForwardView(ADD_CLASS_JSP);
		return SUCCESS;
	}
	
	public String toList(){
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String toAcademy(){
		setForwardView(ACADEMY_JSP);
		return SUCCESS;
	}
	
	public String toMajor(){
		setForwardView(MAJOR_JSP);
		return SUCCESS;
	}
	
	public String toClass(){
		setForwardView(CLASS_JSP);
		return SUCCESS;
	}
	
	public String toEditUnit(){
		info = infoService.findById(info.getId());
		setForwardView(EDIT_UNIT_JSP);
		return SUCCESS;
	}
	
	public String toAddUnit(){
		setForwardView(ADD_UNIT_JSP);
		return SUCCESS;
	}
	
	public String toUnit(){
		setForwardView(UNIT_JSP);
		return SUCCESS;
	}

	public Info getInfo() {
		return info;
	}

	public void setInfo(Info info) {
		this.info = info;
	}

	@Override
	public Info getModel() {
		// TODO Auto-generated method stub
		return info;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		info = new Info();
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	

	
	
	
}
